package com.detu.ivos.vehicle.controller;

import com.detu.ivos.base.response.JsonResult;
import com.detu.ivos.vehicle.pojo.dto.VehicleQuery;
import com.detu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import com.detu.ivos.vehicle.pojo.vo.VehicleVO;
import com.detu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    //搜索列表查询
    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆:vehicleQuery={}", vehicleQuery);
        List<VehicleVO> vehicleVOS = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(vehicleVOS);
    }

    //添加车辆或者更新车辆
    @PostMapping("insert")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        vehicleService.insertAndUpdateVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    //删除车辆
    @PostMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除的id", id);
        vehicleService.deleteVehicleById(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{id}")
    public JsonResult unbind(@PathVariable Long id){
        log.debug("解绑车辆的id"+id);
        vehicleService.unbind(id);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geoId}/{id}")
    public JsonResult bind(@PathVariable Long geoId,@PathVariable Long id){
        log.debug("围栏的id，绑定车辆的id"+geoId+","+id);
        vehicleService.bind(geoId,id);
        return JsonResult.ok();
    }
}
